@layout("/common/_testloginreCommon.html"){
<title>咿呀培训系统 - 注册</title>
<div class="outside">
    <!--logo-->
    <div class="logogif"><img src="http://yiyayl.com/images_1/u16.gif"></div>
    <!--input-->
    <div class="input">
        <input type="text" id="userName" name="firstname form-control" placeholder="请输入用户名"/><br>
        <input type="password" id="passWord" name="password form-control" placeholder="请输入密码"/>
        <input type="password" id="rePassWord" name="password form-control" placeholder="再次输入密码"/>
    </div>
    <!--register-->
    <div class="register">
        <button id="submit_login" type="submit" class="btn btn-default">注册</button>
    </div>
    <!--Reset-->
    <div class="butreset">
        <button type="submit" id="btn_reset" class="btn btn-default">重置</button>
    </div>
    <div class="zhuce">
        <span>返回登录页</span>
    </div>
</div>
<script>
    $('#btn_reset').click(function () {
        document.getElementById('userName').value = "";
        document.getElementById('passWord').value = "";
        document.getElementById('rePassWord').value = "";
    })
    $('.zhuce').unbind().on('click', function () {
        window.location.href = "${ctxPath}/login";
    })
    $('#submit_login').click(function () {
        var userName = $('#userName').val();
        var passWord = $('#passWord').val();
        var rePassWord = $('#rePassWord').val();
        if (userName == "" || userName == null) {
            alert("用户名不能为空!");
            return false;
        }
        if (passWord == "" || passWord == null) {
            alert("密码不能为空!");
            return false;
        }
        if (userName.length > 10) {
            alert("用户名長度不大于10！");
            return false;
        }
        if (passWord.length > 20) {
            alert("注册密码長度不大于20！");
            return false;
        }
        if (passWord != rePassWord) {
            alert("密码不一致!");
            return false;
        }
        $.ajax({
            url: "${ctxPath}/register",
            type: "post",
            data: {
                "userName": userName,
                "rePassWord": rePassWord,
                "passWord": passWord
            },
            dataType: "json",
            success: function (data) {
                alert('注册成功!');
                window.location.href = "${ctxPath}/login";
            },
            error: function (data) {
                alert('注册失败或账号已存在，请稍后再试!');
            }
        });
    })
</script>
@}
